﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Navigation;
using Expression.Blend.SampleData.ottawaSampleDataSource;

namespace OttawaTourMap
{
    public partial class StopDetailsPage : PhoneApplicationPage
    {
        public StopDetailsPage()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            string s = "";
            int stopIndex = 0;
            string tourId = null;
            Expression.Blend.SampleData.ottawaSampleDataSource.tour selectedTour = null;
            var toursSource = (toursList)App.Current.Resources["OttawaSampleDataSource"];

            if (NavigationContext.QueryString.TryGetValue("tourIndex", out s))
            {
                tourId = (s);
               
                //Get the selected tour inforamtion from the id
                //Iterate through the collection
               
                foreach (var tour in toursSource.tourCollection)
                {
                    if (tour.id.Equals(tourId))
                    {
                        selectedTour = tour;
                        break;
                    }
                }

              
            }

            if (NavigationContext.QueryString.TryGetValue("stopIndex", out s))
            {
                stopIndex = int.Parse(s);
            }

            DataContext = selectedTour.stopCollection[stopIndex];
        }
    }
}